/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hoja.de.trabajo.pkg6;

/**
 *
 * @author CarlosAndre
 */

public class Nodo<T> {
    static MinMax myHeap = new MinMaxHeap(50);
    private int cont;
    private int repet ;
    private String code;
    private T dato;
    private Nodo left;
    private Nodo  rigth;
    private int repetis[] = new int[50];

    public Nodo(int preval, T dato) {
        this.repet = preval;
        this.dato = dato;
        this.cont= 0;
    }

    public Nodo(T dato) {
        this.dato = dato;
        this.repet = 1;
    }

    public Nodo() {
        this.repet = 0;
    }

    public int getRepet() {
        return repet;
    }

    public void setRepet(int preval) {
        this.repet = preval;
    }

    public void incRepet() {
        this.repet ++;
    }

    public T getDato() {
        return dato;
    }

    public void setDato(T dato) {
        this.dato = dato;
    }

    public Nodo getLeft() {
        return left;
    }

    public void setLeft(Nodo izq) {
        left = izq;
    }

    public Nodo getRigth() {
        return rigth;
    }

    public void setRigth(Nodo der) {
        rigth = der;
    }

    public String getCode() {
        return code;
    }
    
    @Override
    public String toString() {
        return ("" + getDato());
    }

    public void route(Nodo nodo, String codigo) {
        if(nodo != null) {
            if(nodo.getDato() != null){
                System.out.println("   "+nodo.getDato() + "     |      " + nodo.getRepet()+"      |   " + codigo);
                myHeap.enqueue(new Integer(nodo.getRepet()));
            }
            if(nodo.left != null) {
                code = codigo + "0";
                nodo.route(nodo.left, code);
                
            }
            if(nodo.rigth != null) {
                code = codigo + "1";
                nodo.route(nodo.rigth, code);

            }
      

        }
    }

    public void route() {
                   
            if(left != null) {
                code = "0";
                route(left, code);

            }
            if(rigth != null) {
                code = "1";
                route(rigth, code);

            }
       
    }
   
    public void heap(){
        Integer min= (Integer)myHeap.min();
        Integer max = (Integer)myHeap.max();
        System.out.print("Minimo " + min + " ");
    }
}
